/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
	v1 "k8s.io/api/batch/v1"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.

// RabbitJobSpec defines the desired state of RabbitJob
type RabbitJobSpec struct {
	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
	// Important: Run "make" to regenerate code after modifying this file

	Replicas int32 `json:"replicas,omitempty"`
	//Mqurl is the address of rabbitMq server
	Mqurl string `json:"mqurl,omitempty"`
	//Min is the least pods number to afford the working
	Min int32 `json:"min,omitempty"`
	//Max is the most count even if the request is too much
	Max int32 `json:"max,omitempty"`
	//Lenthreshold point out the lenth of rabbirMq's message queue,
	//if status lower than it, delete Job , and create job if more than it.
	Lenthreshold int32 `json:"lenthreshold,omitempty"`
	//delete pod which havn't accept any message from server longer than Timethreshould
	Timethreshold int32 `json:"timethreshold,omitempty"`
	//
	Miss int32 `json:"miss,omitempty"`
	//this operator's pod using the queue name
	QueueName string `json:"queuename"`
	//import the native job controller
	Job v1.JobSpec `json:"job,omitempty"`
}

// RabbitJobStatus defines the observed state of RabbitJob
type RabbitJobStatus struct {
	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
	// Important: Run "make" to regenerate code after modifying this file
	//the number of running pods
	Replicas int32 `json:"replicas,omitempty"`

	//timeStamp of last getting information to rabbitmq
	LastGettingTime *metav1.Time `json:"lastGettingTime,omitempty"`

	//created job by rabbitjob
	JobNames []string `json:"jobNames,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// RabbitJob is the Schema for the rabbitjobs API
type RabbitJob struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   RabbitJobSpec   `json:"spec,omitempty"`
	Status RabbitJobStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// RabbitJobList contains a list of RabbitJob
type RabbitJobList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []RabbitJob `json:"items"`
}

func init() {
	SchemeBuilder.Register(&RabbitJob{}, &RabbitJobList{})
}
